package com.uh.calculation.inter.imp;


import com.alibaba.fastjson.JSONObject;
import com.uh.calculation.bean.OperatorVal;
import com.uh.calculation.bean.WarnJiSuanBean;
import com.uh.calculation.inter.Warn;
import com.uh.calculation.operator.HjNumOperator;
import com.uh.calculation.operator.HjOperator;
import com.uh.calculation.operator.TjryOperator;
import com.uh.calculation.util.GetOrganization;
import com.uh.microservice.core.dao.JdbcDao;
import com.uh.summary.enums.RuleEnum;

import java.util.Date;
import java.util.List;
import java.util.Map;

public class TouziImp implements Warn {
    private JdbcDao jdbcDao;
    public WarnJiSuanBean warnJiSuan = null;
    //通用表
    List<Map<String, Object>> TJR206_1ls = null;

    List<Map<String, Object>> HJ_ls = null;

    List<Map<String, Object>> F201_1ls = null;


    //1-本月 营业收入修改比例超过15%，计预警因子50。
    //年报营业收入修改比例超过15%，计预警因子50。（此条仅用于4月年报出来时，但一直触发到该企业被核查或检查为止）
    private String  xgfd="[{dimension:\"A\",field:\"$NEW_VALUE;$NEW_VALUE#m\",formulaBeans:[{formula:\"($NEW_VALUE@$NEW_VALUE#m)/$NEW_VALUE#m>0.15|50\"}]}]";
    private String  xgcs="[{dimension:\"A\",field:\"$NEW_VALUE\",formulaBeans:[{formula:\"$NEW_VALUE>3|50\"}]}]";


    @Override
    public Integer jisuan(WarnJiSuanBean warnJiSuan) {
        this.warnJiSuan = warnJiSuan;
        this.jdbcDao = warnJiSuan.getJdbcDao();
        GetOrganization getOrganization = new GetOrganization(jdbcDao);
        Date lastTime = warnJiSuan.getLastTime();
        TJR206_1ls = getOrganization.getFieldName_206("206", warnJiSuan.getYear(), warnJiSuan.getSurveyobjectid(), lastTime);

        HJ_ls =  getOrganization.gethj("et_8600000002021110107720130", warnJiSuan.getSurveyobjectid());
        F201_1ls = getOrganization.getFieldName("201-1", warnJiSuan.getYear(), warnJiSuan.getSurveyobjectid());

        warnJiSuan.setF201_1ls(F201_1ls);

        //1-本月;本年完成投资;万元

        HjOperator hjOperator = new HjOperator(jdbcDao, warnJiSuan);
        List<OperatorVal> list = JSONObject.parseArray(xgfd, OperatorVal.class);
        //修改一
        warnJiSuan.setIs_hc(false);
        warnJiSuan.setWarnType(RuleEnum.INVEST_EDIT_FREQUENCY_FACTOR_MONTH_DATA.getCode());//风险因子类型
        hjOperator.jisuan(HJ_ls, list,"1-本月;本年完成投资;万元");


        list = JSONObject.parseArray(xgcs, OperatorVal.class);
        HjNumOperator hjNumOperator = new HjNumOperator(jdbcDao, warnJiSuan);
        warnJiSuan.setIs_hc(false);
        warnJiSuan.setWarnType(RuleEnum.INVEST_EDIT_FREQUENCY_FACTOR_DATA.getCode());//风险因子类型
        hjNumOperator.jisuan(HJ_ls, list,"1-本月;本年完成投资;万元");



        //统计人员变动
        TjryOperator tjryOperator = new TjryOperator(jdbcDao, warnJiSuan);
        warnJiSuan.setIs_hc(false);
        warnJiSuan.setWarnType(RuleEnum.INVEST_ABNORMAL_STATISTICS_FACTOR_DATA.getCode());//风险因子类型
        tjryOperator.jisuan(TJR206_1ls, "M1", "B");//填表人字段 206表2021年-M1
        return null;
    }
}
